<%@ page pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/base/taglibs.jsp"%>
<html>
	<head>
		<link href="${ctx}/css/main.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="${ctx}/js/xhEditor/jquery-1.4.2.min.js"></script>
		<script type="text/javascript" src="${ctx}/js/xhEditor/xheditor-zh-cn.min.js"></script>
		<script language="javascript">
			function doDelete(action,id){
				if(confirm('是否确认删除？')){
					location.href = "${ctx}/" + action + "?id=" + id ;
				}
			}
			
			function submitAction(action){
				document.manageForm.action = action ;
				document.manageForm.submit();
			}
			
			function select(action, fileName){
				location.href = "${ctx}/" + action + "?fileName=" + fileName;
			}
			
			function init(){
				document.getElementById("newsTitle").value = "";
				document.getElementById("newsSumary").value = "";
				document.getElementById("newsDetail").value = "";
				document.getElementById("localFile").outerHTML = document.getElementById("localFile").outerHTML;
			}
			
			function saveAction(action) {
				document.getElementById("newsDetail").value = $('#newsDetail').val();
				if(document.getElementById("newsTitle").value == '') {
					alert('请输入新闻标题');
					return ;
				}
				if(document.getElementById("newsSort").value == '') {
					alert('请输入新闻种类');
					return ;
				}
				if(document.getElementById("newsDetail").value == '') {
					alert('请输入新闻内容');
					return ;
				}
				submitAction(action);
			}
			
			function validateFileType() {
				fileName = manageForm.localFile.value;
				fileType = fileName.substr(fileName.lastIndexOf(".")).toLowerCase(); 
				if(fileType != '.jpg' && fileType != '.png' && fileType != '.jpeg' && fileType != '.gif' && fileType != '.bmp'){
					alert('图片文件类型错误');
					manageForm.localFile.outerHTML = manageForm.localFile.outerHTML;
					return false;
				}
			}
		</script>
	</head>
	
	<body>
		<form method="post" action="" name="manageForm" ENCTYPE="multipart/form-data">
			<table border="0" cellspacing="1" cellpadding="3" align="center" width="100%">
				<tr>
					<td class="td11" align="left" colspan="2">
						<input type="button" name="search" value="保存" onClick="saveAction('saveNews.ac')">
						<c:if test="${!empty news.id}">
							&nbsp;&nbsp;<input type="button" name="delete" value="删除" onClick="doDelete('deleteNews.ac','${news.id}')">
						</c:if>
						<c:if test="${empty news.id}">
							&nbsp;&nbsp;<input type="button" name="reset" value="重置" onClick="init()">
						</c:if>
						&nbsp;&nbsp;<input type="button" name="back" value="返回" onClick="submitAction('backToNewsSearch.ac')">
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2">
						新闻标题  <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="100%" class="td2">
						<input type="hidden" name="id" value="${news.id}">
						<input type="hidden" name="fileName" value="${news.fileName}">
						<textarea name="newsTitle" rows="2" cols="80">${news.newsTitle}</textarea>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2">
						新闻摘要
					</td>
					<td width="100%" class="td2">
						<textarea name="newsSumary" rows="4" cols="80">${news.newsSumary}</textarea>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2">
						新闻种类  <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="80%" class="td2">
						<select name="newsSort" id="newsSort" style="width:200px">
							<c:forEach var="code" items="${sessionScope.T_newsSortList}">
								<c:if test="${news.newsSort == code.newsSort}">
									<option value="${code.newsSort}" selected="selected">${code.newsSortName}</option>
								</c:if>
								<c:if test="${news.newsSort != code.newsSort}">
									<option value="${code.newsSort}">${code.newsSortName}</option>
								</c:if>
							</c:forEach>
						</select>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2">
						新闻图片
					</td>
					<td width="20%" class="td2">
						<input type="file" name="localFile" size="40" value="" onchange="validateFileType();">
						<span style="color:red;vertical-align:middle;">&nbsp;&nbsp;&nbsp;&nbsp;图片必须是以jpg,gif,jpeg,png,bmp为后缀的文件</span>
					</td>
				</tr>
				<tr>
					<td width="10%" class="td2">  
						文件
					</td>
					<td width="30%" class="td2">
						<a href="javascript:select('getNewsPhoto.ac','${news.fileName}');">${news.fileName}</a>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2" colspan="2">
						新闻内容  <span style="color:red;vertical-align:middle;">*</span>
					</td>
				</tr>
				<tr>
					<td width="100%" class="td2" colspan="2" align="center">
						<textarea id="newsDetail" name="newsDetail" class="xheditor {tools:'Cut,Copy,Paste,Pastetext,Blocktag,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,SelectAll,Removeformat,Align,List,Outdent,Indent,Link,Unlink,|,Preview,Print,Fullscreen',skin:'vista',width:750,height:380}">
							${news.newsDetail}
						</textarea>
					</td>
				</tr>
			</table>
			<BR>
		</form>
	</body>
</html>